package com.aifast.system.sys.controller;


import com.aifast.common.annotations.AiIdempotent;
import com.aifast.common.base.Controller;
import com.aifast.common.base.R;
import com.aifast.common.layui.LayuiDataTable;
import com.aifast.system.sys.entity.SysDictData;
import com.aifast.system.sys.service.SysDictDataService;
import com.jfinal.kit.Kv;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 字典数据 前端控制器
 * </p>
 *
 * @author fujian
 * @since 2021-12-30
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/sysDictData")
public class SysDictDataController extends Controller {

    private final SysDictDataService sysDictDataService;

    @GetMapping("list")
    public LayuiDataTable list() {
        return sysDictDataService.getDatas(getInt("dictId"), get("dictDataName"), get("dictDataCode"), getPage());
    }

    @AiIdempotent
    @PostMapping("add")
    public R add(SysDictData data) {
        return sysDictDataService.insertOrUpdate(data) ? OK() : ERROR();
    }

    @AiIdempotent
    @PostMapping("batchAdd")
    public R batchAdd(SysDictData data) {
        return sysDictDataService.batchAdd(data) ? OK() : ERROR();
    }

    @AiIdempotent
    @GetMapping("del")
    public R del() {
        return sysDictDataService.del(getInt("id"), get("ids")) ? OK() : ERROR();
    }

    @GetMapping("get")
    public R get(@RequestParam(required = false) String... type) {
        return OK(sysDictDataService.get(type));
    }

    @GetMapping("getTree")
    public R getTree(@RequestParam(required = false) String... type) {
        return OK(sysDictDataService.getTree(type));
    }



}

